package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.tree.TreeVO;
import com.jwsoft.manager.common.vo.addressParse.AddressInfo;
import com.jwsoft.manager.common.vo.eduAddressTreeOriginal.OriginalInfoVO;
import com.jwsoft.manager.core.integration.EduAddressTreeOriginalIntegration;
import com.jwsoft.manager.common.vo.eduAddressTreeOriginal.EduAddressTreeOriginalVO;
import com.jwsoft.manager.common.vo.eduAddressTreeOriginal.EduAddressTreeOriginalKeyVO;
import com.jwsoft.manager.common.vo.eduAddressTreeOriginal.EduAddressTreeOriginalQueryVO;
import com.github.pagehelper.PageInfo;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.jwsoft.manager.core.integration.addressParse.SmartParse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import com.bifang.engine.protect.core.annotation.Idempotent;
import org.springframework.validation.annotation.Validated;
import com.bifang.assistant.common.constants.Validators;

import java.util.List;

/**
 * 地址树参数表网关
 *
 * @author zhiyuan
 * @since 2024-01-08
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "地址树参数表", description = "地址树参数表")
public class EduAddressTreeOriginalController {

    @Autowired
    public EduAddressTreeOriginalIntegration eduAddressTreeOriginalIntegration;
    @Autowired
    private SmartParse smartParse;

    @Operation(summary = "地址树参数表分页查询",description = "地址树参数表分页查询")
    @PostMapping(value = "/addressTreeOriginal0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduAddressTreeOriginalVO>> getList(@RequestBody @Validated EduAddressTreeOriginalQueryVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.getList(vo));
    }

    @Operation(summary = "地址树参数表根据主键查询详情",description = "地址树参数表根据主键查询详情")
    @PostMapping(value = "/addressTreeOriginal0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeOriginalVO> getById(@RequestBody @Validated EduAddressTreeOriginalKeyVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "地址树参数表新增",description = "地址树参数表新增")
    @PostMapping(value = "/addressTreeOriginal0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeOriginalVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduAddressTreeOriginalVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "地址树参数表修改",description = "地址树参数表修改")
    @PostMapping(value = "/addressTreeOriginal0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeOriginalVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduAddressTreeOriginalVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "地址树参数表删除",description = "地址树参数表删除")
    @PostMapping(value = "/addressTreeOriginal0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduAddressTreeOriginalKeyVO vo) {
        eduAddressTreeOriginalIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "地址解析方法",description = "地址解析方法")
    @PostMapping(value = "/addressTreeOriginal0007", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse<AddressInfo> getById(@RequestBody @Validated EduAddressTreeOriginalQueryVO vo) {
        return AppResponse.successData(smartParse.parseAddressInfo(vo.getAreaName()));
    }

    @Operation(summary = "分页获取下级节点(参数表)", description = "分页获取下级节点")
    @PostMapping(value = "/addressTreeOriginal0008", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduAddressTreeOriginalVO>> getListByParentId(@RequestBody @Validated EduAddressTreeOriginalQueryVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.getListByParentId(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "参数表节点保存",description = "参数表节点保存")
    @PostMapping(value = "/addressTreeOriginal0009", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeOriginalVO> saveAddressTreeInfo(@RequestBody @Validated(value = {Validators.Edit.class}) OriginalInfoVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.saveAddressTreeInfo(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "参数表级联查询",description = "参数表级联查询")
    @PostMapping(value = "/addressTreeOriginal0010", produces = "application/json;charset=UTF-8")
    public AppResponse<List<TreeVO>> getCascadeOption(@RequestBody EduAddressTreeOriginalQueryVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.getCascadeOption(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "根据行政区划获取所属街道信息",description = "根据行政区划获取所属街道信息")
    @PostMapping(value = "/addressTreeOriginal0011", produces = "application/json;charset=UTF-8")
    public AppResponse<List<SelectVO>> getStreetByAreaCode(@RequestBody EduAddressTreeOriginalQueryVO vo) {
        return AppResponse.successData(eduAddressTreeOriginalIntegration.getStreetByAreaCode(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "清除参数表缓存",description = "清除参数表缓存")
    @PostMapping(value = "/addressTreeOriginal0012", produces = "application/json;charset=UTF-8")
    public AppResponse<List<SelectVO>> clearTreeCache(@RequestBody BaseVO vo) {
        eduAddressTreeOriginalIntegration.clearTreeCache(vo);
        return AppResponse.successMsg("清除成功！");
    }
}
